home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
TAWUG
/
TAWUG Disk No. 56 (SHK)
/
TAWUG56.shk
/
PASCAL.DISKS
(
.txt
)
< prev
next >
Wrap
AppleWorks Document
|
1987-07-01
|
8KB
|
130 lines
O=====|====|====|====|====|====|====|====|====|====|====|====|====|====|====|===
PASCAL - THE CASE OF THE BLOWN DISK
by Jim Wrenholt
Reprinted from The Scarlett Letter'
Published by the Big Apple User Group
H I've been spending my spare time lately learning my way around the P
NPascal system on my Apple. After reading through an introductory book on the O
Msubject, I thought myself ready to study some actual Pascal programs. Well, L
Jafter five minutes of fiddling around I succeeded only in obliterating my N
Ldisk's directory. I still don't know what magical set of keystrokes causes
the disaster.
L Being a veteran of such DOS catastrophies, my first thought was to get J
Hout my Disk ZAP and fix the disk. Pascal lives on the disk in 16 sector P
Nformat so that my ZAP (track/sector read/write routine) is capable of reading G
Eit. After spending a little time looking, I became convinced that my O
Mprogram's textfiles were still intact and that only the directory was messed
L Now to rebuild the directory. First I needed to discover the layout of P
Nthe directory. Pascal is not DOS and the Pascal referance manuals are not as P
Ncomplete as the DOS manuel either. So scrounging through my old magazines, I O
Mturned up an article in CALL APPLE from March/April 1981 that showed how the '
directory is formatted on the disk.
N All that is needed is a name and the beginning and ending block number. N
LPascal numbers are stored in consecutive blocks so there is no track/sector K
Ilist to locate. But since Disk ZAP deals in tracks and sectors the real I
Gchallenge became to discover how the block numbers are mapped onto the O
track/sectors. The results of my sleuthing are shown in the following table.
BLOCK # FIRST SECOND%
TRACK/SECTOR TRACK/SECTOR
x0 y/O y/E
x1 y/D y/C
x2 y/B y/A
x3 y/9 y/8
x4 y/7 y/6
x5 y/5 y/4
x6 y/3 y/2
x7 y/1 y/F
x8 z/O z/E
x9 z/D z/C
xA z/B z/A
xB z/9 z/8
xC z/7 z/6
xD z/5 z/4
xE z/3 z/2
xF z/1 z/F
Where y = 2 * x and z = 2 * x + 1
K It turns out that this block number to track/sector mapping is rather =
twisted. Remember that it takes two sectors for one block.
L To convert from block number to track/sector you must think in hex, or N
Lat least convert. For instance, to find block number $53 on the disk, find O
MX3 in the first column. Then X is $5 in our case. Now double X to get Y, P
NY = 2 * X = 2 * $5 = $A. Finally, the next two columns give the track/sector P
Npair, Y/9 and Y/8. In our example Y = $A, so sectors 9 and 8 on track $A are
the desired locations.
J As another example, let's locate block $3C. First, locate XC in the M
Kfirst column. Using the formula, X = 2 * 3 +1 = 7 so the block is found on
sectors 7 and 6 of track 7.
N To go the other way you must decide if the track is even or odd. If the M
track is even, use the top half of the chart; if odd, use the bottom half.
C For an example of this, let's find the block corresponding to P
Ntrack/sector $OC/$OF. First $OC is an even number so use the top half of the P
Ntable. Next X = $OC/2 = $6. Locating Y/F in the top half and moving over to O
Mthe first column shows that track/sector $OC/$OF is the second half of block
number $67.
N There is just one more thing to be remembered. When you find the start of N
Lyour actual text on the disk you need to back up 2 blocks to leave room for P
Nthe header which is at the start of all text files. For more information see E
the Apple Pascal Reference Manual 3.2.1. The Format of Text Files.
L Now to rebuild the directory. First make a backup of your disk. I use P
NCOPYA from the DOS System Master for this. Of course, if I would have backed O
Mup in the very beginning I would not have had to go through all of this, but I
Gthat's hindsight. Any direction modification of sectors is considered /
dangerous so we need to back up now for sure.
L The Pascal disk directory is divided into entries that are 26 (decimal) F
Dbytes long. The first 26 bytes are for the disk volume name. Each P
Nsubsequent group of 26 bytes is for an individual file. The directory starts P
Non track $O, sector $B and extends downward. There is room for up to 77 file
names.
THE FIRST 26 BYTES
BYTE *
1,0 START OF DIRECTORY$
3,2 END OF DIRECTORY BLOCKNUMBER
5,4 ALWAYS ZERO"
6 LENGTH OF DISK VOLUME NAME
7-13 DISK VOLUME NAME STRING
15,14 NUMBER OF BLOCKS ON DISK
17,16 ENTRIES IN THE DIRECTORY
19,18 ALWAYS ZERO
21,20 CURRENT DATE
23,22 ALWAYS ZERO
25,26 ALWAYS ZERO
INDIVIDUAL FILES
BYTE *
1,0 BLOCK START NUMBER
3,2 BLOCK END NUMBER
5,4 FILE TYPE:
2=CODE, 3=TEXT, 5=DATA
6 LENGTH OF FILE NAME
7-21 FILENAME STRING%
23,22 NUMBER OF BYTES IN LAST BLOCK
25,24 FILE DATE
K As an example, I have included a sector dump of my Apple 1 diskette. O
MNotice, as usual, the low order byte is first. Also the ending block number O
Mis really the beginning of the next file or one block past the actual end of
the text file.
N Let's look at the initial 26 bytes first. The start of the directory is N
L0000, or block zero. The end of the directory is 0600, or block six. Next Q
Owe find two bytes of filler, 00 00. Now 06 is the length of the volume name. 0
The volume name itself appears as shown below.
41 50 50 4C 45 31
A P P L E 1
K Next comes three more filler bytes 00 18 01, followed by a 0A00 which P
Nshows that there are 10 file entries in my current directory. Two more bytes N
Lof filler, 00 00 are followed by the current date in Pascal format, 2C A5. '
The next four bytes are again filler.
M The first individual file is my SYSTEM.APPLE is broken down like this. G
EThe starting block number is six, 06 00. The ending block number is L
Jthirty-eight or hex $26, 26 00. The file type is 05 00 which indicates a P
Ndata file. The length of the data file is twelve, $0C. The file name string
53 59 53 54 45 4D 2E 41 50 50 4C 45$
S Y S T E M . A P P L E
H There are a remaining three bytes of filler 00 24 67. The maximum L
Jlength for a file name is fifteen bytes. The number of bytes in the last H
Fblock is 00 02, which says all the bytes in the last block are used. O
MRemember 00 02 is low order byte first, so it stands for 2 * 256 = 512 bytes P
Nwhich is a full block. This was the case for all the text files I have dealt >
with. Finally there are two bytes for the file date, 9B A0.
L These examples will serve as an entrance into the understanding of how M
KPascal formats information in track/sector blocks. Back up your disks and ;
you will need not to use this information in desperation.